package com.example;

import com.example.dal.entity.DemoAuthor;
import com.example.dal.entity.DemoAuthorExample;
import com.example.dal.mapper.DemoAuthorMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@MapperScan(basePackages="com.example.dal.mapper")
//@ImportResource(locations="classpath:com.example.*.xml")
public class AppAnnoTation implements CommandLineRunner
{

    private final DemoAuthorMapper demoAuthorMapper;

    public AppAnnoTation(DemoAuthorMapper demoAuthorMapper) {
        this.demoAuthorMapper = demoAuthorMapper;
    }

    public static void main( String[] args )
    {
        SpringApplication.run(AppAnnoTation.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("===========");
//        LocalDateTime localDateTime = LocalDateTime.now();
//        DemoAuthor demoAuthor = new DemoAuthor(null,"xiaoAnnotation", localDateTime,localDateTime);
//        demoAuthorMapper.insert(demoAuthor);

        DemoAuthorExample example = new DemoAuthorExample();
        example.createCriteria().andNameEqualTo("xiaoAnnotation");
        List<DemoAuthor>  list=demoAuthorMapper.selectByExample(example);
        list.stream().forEach(v-> System.out.println("---->" + v.getName()));
    }
}
